package com.factory.test.util;

import android.content.Context;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateTimeUtil {

    //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    public static String getCurrentTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sdf.format(new Date());
    }

    public static String getFormatTime(Date date){
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
        return timeFormat.format(date);
    }

    public static String getFormatDate(Date date, Context context){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd EEE", Locale.getDefault());
        return dateFormat.format(date);
    }

    public static String getCurrentTime(String format){
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
        return sdf.format(new Date());
    }


    public static String format(Date date, String pattern){
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.getDefault());
        return sdf.format(date);
    }

    public static String getCurrentTimeZone() {
        TimeZone tz = TimeZone.getDefault();
        return tz.getDisplayName(false, TimeZone.SHORT);
    }



    /**
     * 获取指定天数前的日期
     * @param d
     * @param format
     * @return
     */
    public static String getBeforeDate(int d, String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -d);
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取指定天数前的日期
     * @param d
     * @return
     */
    public static Date getBeforeDate(int d) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -d);
        return calendar.getTime();
    }
}
